package com.fishingwithme.android.ui.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.fishingwithme.android.data.model.PointsRecord
import com.fishingwithme.android.data.repository.FishingRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class CreditRecordsViewModel @Inject constructor(
    private val repository: FishingRepository
) : ViewModel() {

    private val pager = Pager(
        config = PagingConfig(
            pageSize = 60, // Updated to match what the API actually returns
            enablePlaceholders = false
        ),
        pagingSourceFactory = {
            CreditRecordsPagingSource(repository)
        }
    )

    val creditRecords: Flow<PagingData<PointsRecord>> = pager.flow.cachedIn(viewModelScope)
}